<template>
	<view v-if="list != ''">
		<view class="15">
			<u-index-list :scrollTop="scrollTop">
				<view  v-for="(item, index) in indexList" :key="index">
					<u-index-anchor  :custom-style ="{fontWeight: '600'}" :index="item" />
					<view class="p10" @click="xuan(it)" v-if="it.zimu == item"  v-for="(it, index1) in list" :key="index1">
						{{it.name}}
					</view>
				</view>
			</u-index-list>
		</view>
		<u-select v-model="chexing_show" mode="single-column"  :list="chexing_list"
			@confirm="chexing_confirm"></u-select>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				chexing_show:false,
				scrollTop: 0,
				indexList: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
					"V", "W", "X", "Y", "Z"
				],
				list:[],
				chexing_list:[],
				brand:'',
				model:'',
				chexing_id:''
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			init(){
				//获取车型
				this.$http.post(this.$config.UrlPostcarList, {}).then((res) => {
					if (res.status == 1) {
						this.list = res.data
					}
				
				})
			},
			onPageScroll(e) {
				this.scrollTop = e.scrollTop;
			},
			xuan(item){
				this.brand = item.name
				var json={
					pid:item.id
				}
				this.$http.post(this.$config.UrlPostcarxhList, json).then((res) => {
					if (res.status == 1) {
						this.chexing_list = res.data
						if(res.data != ''){
							this.chexing_show = !this.chexing_show
						}else{
							// this.$api.toast("暂无该品牌车型")
							uni.setStorageSync('brand', this.brand);
							uni.removeStorageSync('model');
							uni.setStorageSync('chexing_id',item.id);
							this.$api.back()
						}
						
					}
				
				})
			},
			chexing_confirm(e){
				this.model = e[0].label
				this.chexing_id = e[0].value
				uni.setStorageSync('brand', this.brand);
				uni.setStorageSync('model', this.model);
				uni.setStorageSync('chexing_id', this.chexing_id);
				this.$api.back()
			}
		}
	}
</script>

<style>
page {
		background: #ffffff;
		color: #333333;
	}
</style>
